package gold.digger;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC118 {


    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> res = new ArrayList<>();
        if (numRows <= 0) {
            return res;
        }

        res.add(new ArrayList<>(Arrays.asList(1)));
        for (int i = 2; i <= numRows; i++) {
            List<Integer> curLine = new ArrayList<>();
            curLine.add(1);//first start 1
            List<Integer> lastLine = res.get(res.size() - 1);
            for (int j = 0; j <= i - 3; j++) {
                curLine.add(lastLine.get(j) + lastLine.get(j + 1));
            }
            curLine.add(1);//last end 1
            res.add(curLine);
        }

        return res;
    }

    public static void main(String[] args) {
        String test = "abbbbacd";
        LC118 an = new LC118();
        System.out.println(an.generate(5));
    }
}
